package com.xdap.dao;

import com.definesys.mpaas.query.MpaasQuery;
import com.xdap.common.utils.AbsDao;
import com.xdap.pojo.jimu.JimuReportDbFieldPo;
import com.xdap.runtime.service.RuntimeDatasourceService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ReportDbFieldDao  extends AbsDao<JimuReportDbFieldPo> {

    @Autowired
    private RuntimeDatasourceService runtimeDatasourceService;

    @Value("${spring.datasource.name}")
    private String datasourceName;

    public List<JimuReportDbFieldPo> findByReportDbIds(List<String> reportDbIds) {
        MpaasQuery mpaasQuery = runtimeDatasourceService.buildTenantMpaasQuery(datasourceName);
        List<JimuReportDbFieldPo> result = null;
        if(CollectionUtils.isNotEmpty(reportDbIds)){
            result =  mpaasQuery.in("jimu_report_db_id", reportDbIds).doQuery(JimuReportDbFieldPo.class);
        }else{
            result =   mpaasQuery.isNotNull("jimu_report_db_id").doQuery(JimuReportDbFieldPo.class);
        }
        return result;
    }
}
